#include "binaryhelper.h"
#include <string>
#include <fstream>
#include <stdint.h>

void BinaryHelper::EndianSwap(int headers[], int size)
{
    for (int i = 0; i <= size; i++)
    {
        headers[i] = _byteswap_ulong(headers[i]);
    }
}

void BinaryHelper::EndianSwap(int headers[], int size, int intLength)
{
    for (int i = 0; i < intLength; i++)
    {
        headers[i] = _byteswap_ulong(headers[i]);
    }

    for (int i = intLength; i < size; i++)
    {
        headers[i] = _byteswap_ushort(headers[i]);
    }
}

string BinaryHelper::ReadString(ifstream &fstream)
{
    long tmp = fstream.tellg();
    while(true)
    {
        uint8_t b;
        fstream.read((char *)&b, 1);

        if(b == 0)
            break;
    }

    long tmp2 = fstream.tellg();
    fstream.seekg(tmp, ios_base::beg);
    char arr[100000];
    fstream.read((char*)arr, (tmp2 - tmp));
    string str(arr);

    return str;
}

BinaryHelper::BinaryHelper()
{

}



